package com.bvgol.examples.nio.zerocp.nio;/**
 * @Classname Client
 * @Description TODO
 * @Date 2021/7/6 10:27
 * @Created by GUOCHEN
 */

import lombok.SneakyThrows;

import java.io.FileInputStream;
import java.net.InetSocketAddress;
import java.nio.channels.FileChannel;
import java.nio.channels.SocketChannel;

/**
 * @program: my-spring-completely
 * @description:
 * @author: GUOCHEN
 * @create: 2021/07/06 10:27
 */
public class Client {
    @SneakyThrows
    public static void main(String[] args) {
        SocketChannel open = SocketChannel.open();
        open.connect(new InetSocketAddress("localhost",7001));
        String filename = "D:\\idea_projects\\my-springboot-completely\\netty\\src\\main\\resources\\file01.txt";
        FileChannel channel = new FileInputStream(filename).getChannel();

        long startTime = System.currentTimeMillis();

        /*
        linux ---? transferTo
        win  -->  transferTo 一次传输8m,需要分段和循环
         */
        long transferTo = channel. transferTo(0, channel.size(), channel);

        System.out.println("transferTo = " + transferTo);
        System.out.println("历时 = " + (System.currentTimeMillis()-startTime));
        channel.close();
        open.close();
    }
}
